﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using web1000.Model;
using web1000.Model.Entity;

namespace ConsoleApp1
{
	public class DbInitalizer : System.Data.Entity.DropCreateDatabaseAlways<Admin1000Context>
	{
		protected override void Seed(Admin1000Context context)
		{
			var product1 = new Product
			{
				ProductName = "羊皮卷",
				Price = 25.0m
			};
			var product2 = new Product
			{
				ProductName = "大主宰",
				Price = 45.0m
			};

			context.Products.Add(product1);
			context.Products.Add(product2);
			context.SaveChanges();

			var stock1 = new Stock
			{
				ProductId = product1.Id,
				StockNumber = 1234
			};
			var stock2 = new Stock
			{
				ProductId = product2.Id,
				StockNumber = 4561
			};
			context.Stocks.Add(stock1);
			context.Stocks.Add(stock2);
			context.SaveChanges();

			var market1 = new BookMarket
			{
				ProductId = product1.Id,
				StockId = stock1.Id,
				SellNumber = 12,
				SellPrice = 12 * product1.Price
			};


			var market2 = new BookMarket
			{
				ProductId = product2.Id,
				StockId = stock2.Id,
				SellNumber = 54,
				SellPrice = 54 * product1.Price
			};
			context.Markets.Add(market1);
			context.Markets.Add(market2);
			context.SaveChanges();

			base.Seed(context);
		}
	}
}
